<?
    class PrincipioLab_Tools
    {
        const HASH_LENGTH = 128;

        const BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";


        public static function hash($value)
        {
            return hash("md5", $value);
        }


        public static function genHashRnd()
        {
            $hash = "";

            $base64_alphabet = self::BASE64_ALPHABET;

            for($i = 0; $i < self::HASH_LENGTH; $i++)
                $hash .= $base64_alphabet[rand(0, strlen(self::BASE64_ALPHABET) - 1)];

            return self::hash($hash);
        }


        public static function genHash($hash_length)
        {
            $hash = self::genHashRnd().self::genHashRnd();

            $new_hash = "";

            for ($i = 0; $i < intval($hash_length); $i++)
                $new_hash .= $hash[rand(0, strlen(self::BASE64_ALPHABET) - 1)];

            return $new_hash;
        }
    }
?>